﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSSystem.DAL;

namespace POSSystem.BLL
{
    public class RepairStatusHistories : _RepairStatusHistories
    {
        public static RepairStatusHistories GetLastestStatusAfter(int jobID, int curStatusID)
        {
            try
            {
                RepairStatusHistories hist = new RepairStatusHistories();
                hist.Where.RepairJobID.Value = jobID;
                hist.Where.RepairStatusID.Value = curStatusID;
                hist.Where.RepairStatusID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.NotEqual;
                hist.Query.Top = 1;
                hist.Query.AddOrderBy(RepairStatusHistories.ColumnNames.UpdatedDate, MyGeneration.dOOdads.WhereParameter.Dir.DESC);
                hist.Query.Load();

                return hist;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("RepairStatusHistories.cs", "GetLastestStatusAfter", ex.Message + " " + ex.StackTrace);
                throw ex;
            }
        }

        public static void DeleteStatusByJobId(int jobID)
        {
            try
            {
                RepairStatusHistories hist = new RepairStatusHistories();
                hist.Where.RepairJobID.Value = jobID;
                hist.Query.Load();
                hist.DeleteAll();
                hist.Save();
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("RepairStatusHistories.cs", "GetLastestStatusAfter", ex.Message + " " + ex.StackTrace);
                throw ex;
            }
        }
    }
}
